<style type="text/css">
.thumbnail
{
float:left;
margin:30px;
}
table,th,td
{
border:1px solid #D4D4D4;
border-collapse: collapse;
border-color: gray;
}
.text_line
{
clear:both;
}
span
{
    cursor: pointer;
    color: #0398CA;
}
span:hover
{
    color: red;
}
</style>
<script src="<?php echo $this->baseURL()."/media/js/jquery-1.8.2.js"; ?>" type="text/javascript"></script>
<script>
    function adminEditFunction(idStudent)
    {
        $.ajax({
            url:"/TutorProfile/public/student/admin",
            data:{command:'edit', id: idStudent},
            type:"GET",
            success: function(data)
            {
                window.location.href = "/TutorProfile/public/student/editadmin/".concat(idStudent);
            }
        });
    }
    
    function adminEnDisableFunction(obj,idStudent)
    {
        var confirmed = confirm("Bạn thực sự muốn chuyển trạng thái của sinh viên này?");
        if(confirmed)
        {
            $.ajax({
                url:"/TutorProfile/public/student/admin",
                data:{command:'endisable', id: idStudent},
                type:"GET",
                success: function(data)
                {
                    if(data == 1)
                    {
                        obj.innerHTML = '[Enable]';
                        var myLabel = 'myLabel'.concat(idStudent);
                        document.getElementById(myLabel).innerHTML = "<span style='color:white; background-color: red; padding-left:5px;padding-right: 5px;';>Đã đi dạy</span>";

                    }

                    else
                    {
                        obj.innerHTML = '[Disable]';
                        var myLabel = 'myLabel'.concat(idStudent);
                        document.getElementById(myLabel).innerHTML = "<span style='color:white; background-color: red; padding-left:5px;padding-right: 5px;';>Chưa đi dạy</span>";
                    }

                }
            });

        }
        
    }
</script>

<h2>Quản lý sinh viên</h2>
<table width='900' class='thumbnail'>
    <tr>
        <th>Mã số</th>
        <th>Họ tên</th>
        <th>Email</th>
        <th>Số điện thoại</th>
        <th>Ngày tạo</th>
        <th>Trạng thái</th>
        <th>Thao tác</th>
    </tr>
<?php
foreach($this->data as $item)
{
     if ($item['status'] == 0)
    {
        $status = '[Disable]';
        $statusLabel = "Chưa đi dạy";
    }
    else
    {
        $status = '[Enable]';
        $statusLabel = "Đã đi dạy";
    }
    
    echo "<tr>";
    echo "<td>";
    echo $item['id'];
    echo "</td>";
    echo "<td>";
    echo "<b><span style='color:blue';>".$item['username']."</span></b>";
    echo "</td>";
    echo "<td>";
    echo $item['email'];
    echo "</td>";
    echo "<td>";
    echo $item['phonenumber'];
    echo "</td>";
    echo "<td>";
    echo $item['created'];
    echo "</td>";
    echo "<td>";
    echo "<p id='myLabel".$item['id']."'><span style='color:white; background-color: red; padding-left:5px;padding-right: 5px;';>".$statusLabel."</span></p>";
    echo "</td>";
    echo "<td>";
    echo "<a href='".$this->url(array('controller'=>'student', 'action'=>'editadmin', 'studentid' => $item['id']),null,true)."'>[Edit]</a>|";
   
    
    echo "<a href='#' onclick='adminEnDisableFunction(this,".$item['id'].")'>".$status."</a>";
    echo "</td>";
    echo "</tr>";
}
?>
</table>
<br />
<div class="text_line">
<?php
       echo $this->paginationControl($this->data, 'Sliding' , 'student/pagination.phtml');
?>
</div>